package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;
import java.util.Scanner;
public class A_2023A_3122__贪心_快递货车 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int[] weights = Arrays.stream(sc.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
			int limit = Integer.parseInt(sc.nextLine());

			System.out.println(getResult(weights, limit));
		}

		public static int getResult(int[] weights, int limit) {
			Arrays.sort(weights);

			int count = 0;
			int sum = 0;
			for (int w : weights) {
				// 每次都选择重量最小的快递加入
				sum += w;
				if (sum > limit) break;
				count++;
			}

			return count;
		}
	}